package com.tang.h2_demo.global;

public class ResultBuilder {
    public static Result DEFAULT_RESULT = null;

    static {
        DEFAULT_RESULT = new Result();
        DEFAULT_RESULT.setCode(400);
        DEFAULT_RESULT.setData(null);
        DEFAULT_RESULT.setMsg("success");
    }

    private Object data;
    private Integer code;
    private String msg;

    public ResultBuilder setData(Object data) {
        this.data = data;
        return this;
    }

    public ResultBuilder setCode(Integer code) {
        this.code = code;
        return this;
    }

    public ResultBuilder setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public Result builder() {
        Result result = new Result();
        result.setCode(this.code);
        result.setData(this.data);
        result.setMsg(this.msg);
        return result;

    }

    public static Result builderDefaultSuccess(Object data) {
        Result result = new Result();
        result.setCode(200);
        result.setData(data);
        result.setMsg("success");
        return result;
    }

    public static Result builderDefaultError(Object data) {
        Result result = new Result();
        result.setCode(400);
        result.setData(data);
        result.setMsg("error");
        return result;
    }
}
